/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gesturetracking;

import java.awt.Button;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JPanel;
import org.OpenNI.Point3D;

/**
 *
 * @author xvanek9
 */
public class ButtonPanel extends JPanel {
    
    private Button b1, b2, b3, b4, b5, b6, b7, b8, b9;
    public ButtonPanel(){

        super(new GridLayout(3,3,20,20));
        this.setSize(640, 480);
        b1 = new Button("b1");
        b1.setSize(200, 150);
        b2 = new Button("b2");
        b2.setSize(200, 150);
        b3 = new Button("b3");
        b3.setSize(200, 150);
        b4 = new Button("b4");
        b4.setSize(200, 150);
        b5 = new Button("b5");
        b5.setSize(200, 150);
        b6 = new Button("b6");
        b6.setSize(200, 150);
        b7 = new Button("b7");
        b7.setSize(200, 150);
        b8 = new Button("b8");
        b8.setSize(200, 150);
        b9 = new Button("b9");
        b9.setSize(200, 150);
        
        this.add(b1);
        this.add(b2);
        this.add(b3);
        this.add(b4);
        this.add(b5);
        this.add(b6);
        this.add(b7);
        this.add(b8);
        this.add(b9);

    }
    
    public void pushButton(Point3D points){
        int x = (int) points.getX();
        int y = (int) points.getY();
    
        if (x < -400){
            if (y < 470){
                b7.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256), (int)(Math.random()*256)));
            }else if ( y < 640){
                b4.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256), (int)(Math.random()*256)));
            }else b1.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256), (int)(Math.random()*256)));
        }
                if (Math.abs(x) < 400){
            if (y < 470){
                b8.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256), (int)(Math.random()*256)));
            }else if ( y < 640){
                b5.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256), (int)(Math.random()*256)));
            }else b2.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256), (int)(Math.random()*256)));
        }
        if (x > 400){
            if (y < 470){
                b9.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256), (int)(Math.random()*256)));
            }else if ( y < 640){
                b6.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256), (int)(Math.random()*256)));
            }else b3.setBackground(new Color((int)(Math.random()*256),(int)(Math.random()*256), (int)(Math.random()*256)));
        }
    }
    }
        

